<?php
/**
 * 全局类调用,显示后台信息公共部分
 * BaseController.php
 */
namespace app\admin\controller;
use think\Controller;
use think\Session;
use app\common\controller\ShopService as ShopService;
use app\common\controller\AdminService as AdminService;
use app\admin\model\Goods as goodsModel;
use app\admin\model\Goods_category as categoryModel;
use app\admin\model\Goods_brand as brandModel;
use app\admin\model\GoodsType as typeModel;
use app\admin\model\GoodsSpec as specModel;
use app\admin\model\Pictures as picsModel;
use app\admin\model\SpecItem as specItemModel;
class BaseController extends Controller
{

    protected $user = null;

    protected $website = null;

    protected $uid;

    protected $instance_id;

    protected $instance_name;

    protected $user_name;

    protected $user_headimg;

    protected $module = null;

    protected $controller = null;

    protected $action = null;

    protected $module_info = null;

    protected $rootid = null;

    protected $moduleid = null;
    public function __construct()
    {
        parent::__construct();
        // $this->user = new User();
        // $this->website = new WebSite();
        $this->categoryModel=new categoryModel;
        $this->brandModel=new brandModel;
        $this->goodsTypeModel=new typeModel;
        $this->specModel=new specModel;
        $this->specItemModel= new specItemModel;
        $this->adminUser=new AdminService;
        $this->shopServ=new ShopService;
        $this->init();
    }
    /**
     * 创建时间：2017-8-3
     * 功能说明：调用加载头部数据的方法
     */
    public function init()
    {
        //登陆信息
        $name=Session::get('name');
        $id=Session::get('id');
        if($name && $id){
            $userInfo=$this->adminUser->selectAdminUser($id);
            $shopConfigInfo=$this->shopServ->getConfigInfo();
            $this->assign('userInfo',$userInfo);
            $this->assign('shopInfo',$shopConfigInfo);
        }else{
            $this->error('您还没有登录','admin/login/index');
        }        
    }

    /**
     * 添加操作日志（当前考虑所有操作），
     */
    private function addUserLog()
    {
        $get_data = '';
        if ($_GET) {
            $res = \think\Request::instance()->get();
            $get_data = json_encode($res);
        }
        if ($_POST) {
            $res = \think\Request::instance()->post();
            if (empty($get_data)) {
                $get_data = json_encode($res);
            } else {
                $get_data = $get_data . ',' . json_encode($res);
            }
        }
        // 建议，调试模式，用于
        // $res = $this->user->addUserLog($this->uid, 1, $this->controller, $this->action, \think\Request::instance()->ip(), $get_data);
    }

    /**
     * 获取导航
     */
    public function getNavigation()
    {
        $first_list = $this->user->getchildModuleQuery(0);
        $list = array();
        foreach ($first_list as $k => $v) {
            $submenu = $this->user->getchildModuleQuery($v['module_id']);
            $list[$k]['data'] = $v;
            $list[$k]['sub_menu'] = $submenu;
        }
        $this->assign("nav_list", $list);
    }
}
